#coding:utf-8
#再次修改
import sys
from PyQt5 import uic
from PyQt5.QtWidgets  import QApplication
from PyQt5.QtWidgets import QMainWindow

class Calc(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.x = None
        self.y = None
        self.result = None
        self.equal = None
        self.operator = None
        self.clear = None

        uic.loadUi('calc.ui',self)
        self.pushButton0.clicked.connect(self.click_on_button)
        self.pushButton1.clicked.connect(self.click_on_button)
        self.pushButton2.clicked.connect(self.click_on_button)
        self.pushButton3.clicked.connect(self.click_on_button)
        self.pushButton4.clicked.connect(self.click_on_button)
        self.pushButton5.clicked.connect(self.click_on_button)
        self.pushButton6.clicked.connect(self.click_on_button)
        self.pushButton7.clicked.connect(self.click_on_button)
        self.pushButton8.clicked.connect(self.click_on_button)
        self.pushButton9.clicked.connect(self.click_on_button)
        self.pushButton_clear.clicked.connect(self.click_on_button)
        self.pushButton_add.clicked.connect(self.click_on_button)
        self.pushButton_sub.clicked.connect(self.click_on_button)
        self.pushButton_div.clicked.connect(self.click_on_button)
        self.pushButton_mul.clicked.connect(self.click_on_button)
        self.pushButton_dot.clicked.connect(self.click_on_button)
        self.pushButton_equal.clicked.connect(self.click_on_button)

    def calculate(self):
        """
        如果x、y、operator不为空，计算结果。
        """
        if self.x and self.operator and self.y:
            self.result = str(eval("%s%s%s"%(self.x,self.operator,self.y)))
            self.text_result.setText(self.result)
    def click_on_button(self):
        value = self.sender().text()
        #如果点击的是数字，print数字
        if value in "0123456789.":
            print value
        #如果点击的是运算符，print运算符
        if value in "-+*/":
            print value 

        #如果点击的是=，print =
        if value in "=":
            print  value 
        #如果点击的是c, print None
        if value in "c":
            print None
        
        
if __name__ == '__main__':    
    app = QApplication(sys.argv)
    calc = Calc()
    calc.x = "1"
    calc.y = "5"
    calc.operator = "+"
    calc.calculate()
    calc.show()
    app.exec_()




